package cn.sjtu.java_util_concurrent.lock;

/**
 * @author syo 2319615164@qq.com
 * @description 打破死锁
 * @date 2024/6/12
 * @Copyright syo
 */
public class TestBrokeDeadLock {
    private static final Object lock1 = new Object();
    private static final Object lock2 = new Object();
    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (lock1) {
                try {
                    Thread.sleep(1000);
                    synchronized (lock2) {
                        System.out.println("线程1执行了");
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        new Thread(() -> {
            synchronized (lock1) {
                try {
                    Thread.sleep(1000);
                    synchronized (lock2) {
                        System.out.println("线程2执行了");
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
